import 'dart:convert';
import 'dart:io';

import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:panda/base/Constant.dart';
import 'package:panda/jiayouzhan/jyz_list_page.dart';
import 'package:panda/jiayouzhan/jyz_pay_page.dart';
import 'package:panda/util/AppSaveInfoUtil.dart';
import 'package:permission_handler/permission_handler.dart';

class ShopManagerPage extends StatefulWidget {
  ShopManagerPage({Key key}) : super(key: key);

  @override
  _ShopManagerPageState createState() => _ShopManagerPageState();
}

class _ShopManagerPageState extends State<ShopManagerPage> {
  String uid="3";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // check();
    getString(UID).then((value){
      uid=value;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: Text('店长特权',
            style: TextStyle(
                fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                color: Colors.black)),
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
        elevation: 0.5,
      ),
      body: Container(
        padding: EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_20)),
        child: Row(
          children: <Widget>[
            Expanded(
              child: GestureDetector(
                child: Center(
                  child: Column(
                    children: <Widget>[
                      Image.asset("images/jiayouyouhui.png",
                          fit: BoxFit.cover,
                          width: (MediaQuery.of(context).size.width -
                                  ScreenUtil.getInstance().setHeight(DP_60)) /
                              2),
                      // Container(
                      //   height: ScreenUtil.getInstance().setWidth(DP_8),
                      // ),
                      // Text(
                      //   '熊猫加油',
                      //   style: TextStyle(
                      //       color: Colors.black87,
                      //       fontSize: ScreenUtil.getInstance()
                      //           .setSp(SMALL_FONT_SIZE)),
                      // ),
                      // Container(
                      //   height: ScreenUtil.getInstance().setHeight(DP_10),
                      // ),
                      // Container(
                      //   width: ScreenUtil.getInstance().setHeight(DP_40),
                      //   height: ScreenUtil.getInstance().setHeight(3),
                      //   color: white,
                      // )
                    ],
                  ),
                ),
                onTap: () {
                  check();
                },
              ),
            ),
            Container(width: ScreenUtil.getInstance().setHeight(DP_20)),
            Expanded(
              child: GestureDetector(
                child: Center(
                  child: Column(
                    children: <Widget>[
                      Image.asset("images/youhuikaquan.png",
                          fit: BoxFit.cover,
                          width: (MediaQuery.of(context).size.width -
                                  ScreenUtil.getInstance().setHeight(DP_60)) /
                              2),
                      // Container(
                      //   height: ScreenUtil.getInstance().setWidth(DP_8),
                      // ),
                      // Text(
                      //   '熊猫卡券',
                      //   style: TextStyle(
                      //       color: Colors.black87,
                      //       fontSize: ScreenUtil.getInstance()
                      //           .setSp(SMALL_FONT_SIZE)),
                      // ),
                      // Container(
                      //   height: ScreenUtil.getInstance().setHeight(DP_10),
                      // ),
                      // Container(
                      //   width: ScreenUtil.getInstance().setHeight(DP_40),
                      //   height: ScreenUtil.getInstance().setHeight(3),
                      //   color: white,
                      // )
                    ],
                  ),
                ),
                onTap: () {
                  var timeStamp = DateTime.now().millisecondsSinceEpoch;
                  String signstr = "agentId=405&machineCode="+uid+"&timestamp=" +
                      timeStamp.toString();
                  String singstrs =
                      signstr + "&secretKey=Pe7HRBJYwQfpxCb3s5TGW3hXeWxhXKpH";
                  var content = new Utf8Encoder().convert(singstrs);
                  var digest = md5.convert(content);
                  String sign = hex.encode(digest.bytes).toUpperCase();
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          //导航打开新视图
                          builder: (context) => JYZPayPage(
                              url:
                                  "http://tq.jfshou.cn/seller/app/classify?machineCode="+uid+"&agentId=405&timestamp="+timeStamp.toString()+"&sign="+sign) //打开第二个页面，并传值，传递值的名称是model
                          ));
                  //  Navigator.of(context).push(new MaterialPageRoute(builder:(context){
                  //   return SelectTopGoodsPage();
                  // }));
                },
              ),
            ),
            // Expanded(
            //   child: GestureDetector(
            //     child: Center(
            //       child: Column(
            //         children: <Widget>[
            //           Image.asset("images/privilege_menu_c.png"),
            //           Container(
            //             height: ScreenUtil.getInstance().setWidth(DP_8),
            //           ),
            //           Text(
            //             '熊猫学堂',
            //             style: TextStyle(
            //                 color: Colors.black87,
            //                 fontSize: ScreenUtil.getInstance()
            //                     .setSp(SMALL_FONT_SIZE)),
            //           ),
            //           Container(
            //             height: ScreenUtil.getInstance().setHeight(DP_10),
            //           ),
            //           Container(
            //             width: ScreenUtil.getInstance().setHeight(DP_40),
            //             height: ScreenUtil.getInstance().setHeight(3),
            //             color: white,
            //           )
            //         ],
            //       ),
            //     ),
            //     onTap: () {
            //        Navigator.of(context).push(new MaterialPageRoute(builder:(context){
            //         return StudyClassPage();
            //       }));
            //     },
            //   ),
            // ),
            // Expanded(
            //   child: GestureDetector(
            //     child: Center(
            //       child: Column(
            //         children: <Widget>[
            //           Image.asset("images/privilege_menu_d.png"),
            //           Container(
            //             height: ScreenUtil.getInstance().setWidth(DP_8),
            //           ),
            //           Text(
            //             '熊猫游戏',
            //             style: TextStyle(
            //                 color: Colors.black87,
            //                 fontSize: ScreenUtil.getInstance()
            //                     .setSp(SMALL_FONT_SIZE)),
            //           ),
            //           Container(
            //             height: ScreenUtil.getInstance().setHeight(DP_10),
            //           ),
            //           Container(
            //             width: ScreenUtil.getInstance().setHeight(DP_40),
            //             height: ScreenUtil.getInstance().setHeight(3),
            //             color: white,
            //           )
            //         ],
            //       ),
            //     ),
            //     onTap: () {
            //       Fluttertoast.showToast(msg: "敬请期待");
            //     },
            //   ),
            // ),
          ],
        ),
      ),
    );
  }

  check() async {
    if (Platform.isIOS) {
      Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
        return JYZListPage();
      }));
    } else {
      var status = await Permission.location.status;
      if (status.isGranted) {
        // We didn't ask for permission yet.
        Navigator.of(context).push(new MaterialPageRoute(builder: (context) {
          return JYZListPage();
        }));
      }
      if (status.isUndetermined) {
        // We didn't ask for permission yet.
        Permission.location.request();
      }
      if (await Permission.location.isRestricted) {
        // The OS restricts access, for example because of parental controls.
      }
      if (status.isPermanentlyDenied) {
        // The user opted to never again see the permission request dialog for this
        // app. The only way to change the permission's status now is to let the
        // user manually enable it in the system settings.
        openAppSettings();
      }
    }
  }
}
